package cn.edu.zjgsu.ito.controller;
import java.util.ArrayList;
import java.util.List;

import cn.edu.zjgsu.ito.service.ServiceFactory;
import cn.edu.zjgsu.ito.service.TeaRegraceService;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

public class TeaRegraceController extends Controller {
	
	/**
	 * 教师补考成绩录入
	 * 杨昆鹏
	 * */
	TeaRegraceService teaRegraceService = ServiceFactory.createTeaRegraceService();
	
	//补考页面初始化
	public void index(){
		String tNo = getSessionAttr("tNo");
		ArrayList<Record> stuInf = (ArrayList<Record>) teaRegraceService.index(tNo);
		setAttr("stuInf",stuInf);
		render("regraceManage.html");
	}

	//补考成绩导入页面
	public void reGraImport(){
		int flag = 0;
		System.out.println(getPara("uuid"));
		String uuid = getPara("uuid");
		ArrayList<Record> stuInf = (ArrayList<Record>) teaRegraceService.reGraImport(uuid);
		setAttr("stuInf",stuInf);
		System.out.println(stuInf.size());
		
		for(int i=0;i<stuInf.size();i++){
            if(stuInf.get(i).getInt("gradeStatus")==2){
                flag=1;
            }
        }
        System.out.println("jingyong:"+flag);
		if(flag==1){
			System.out.println("禁用按钮");
			setAttr("access","disabled class=\"disabled\"");
		}
		
		render("regrace.html");
	}
	
	//判断是否需要补考课程
	public void produceRepGra(String term,String tNo,String courseNo){
		//有补考的自动生成补考课程
		String regime = "five";//五级制，百分制
//		teaRegraceService.produceRepGra(term,tNo,courseNo);
		
	}
	
	//补考成绩保存
	public void reGraSave(){

		String passportNoes = getPara("passportNo");
		String grades = getPara("grade");
		String termValue = getPara("termValue");
		String courseNo = getPara("courseNo");
		
		System.out.println(passportNoes+"==="+grades+"+++"+termValue+"+++"+courseNo);
		System.out.println(grades+"9999999999999");
		String[] passportNoesss = passportNoes.split(",");
		String[] gradesss = grades.split(",");
		List<Record> stuGra = new ArrayList<Record>();
		for(int i = 0;i < gradesss.length;i++){
			Record stu = new Record();
			System.out.println(gradesss[i]+"88888888888");
			stu.set("grade",gradesss[i]).set("termValue",termValue).set("courseNo",courseNo).set("passportNo", passportNoesss[i]);
			stuGra.add(stu);
		}
		teaRegraceService.saveRepGrade(stuGra);
	}
	
	//补考成绩提交
	public void reSubSave(){
			
		String passportNoes = getPara("passportNo");
		String grades = getPara("grade");
		String termValue = getPara("termValue");
		String courseNo = getPara("courseNo");
		
		System.out.println(passportNoes+"==="+grades+"+++"+termValue+"+++"+courseNo);
		
		String[] passportNoesss = passportNoes.split(",");
		String[] gradesss = grades.split(",");
		List<Record> stuGra = new ArrayList<Record>();
		for(int i = 0;i < gradesss.length;i++){
			Record stu = new Record();
			stu.set("grade",gradesss[i]).set("termValue",termValue).set("courseNo",courseNo).set("passportNo", passportNoesss[i]);
			stuGra.add(stu);
		}
			
		teaRegraceService.subRepGrade(stuGra);	
		
		setAttr("access","disabled");
	}
	
	
}
